package approve.adapter;

import java.text.DecimalFormat;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TableRow;
import android.widget.TextView;
import approve.action.R;
import approve.model.BuyingDocument;

public class PurchaseOrderAdapter extends BaseAdapter{
	private Context context;
	private List<BuyingDocument> lstBuyDoc;
	private Bundle language;
	TableRow flag = null;
	ViewHolder holder;

	public PurchaseOrderAdapter(Context context,
			List<BuyingDocument> lstBuyDoc,Bundle language) {
		super();
		this.context = context;
		this.lstBuyDoc = lstBuyDoc;
		this.language = language;
	}

	@Override
	public int getCount() {
		return lstBuyDoc.size();
	}

	@Override
	public Object getItem(int arg0) {
		return lstBuyDoc.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int arg0, View convertview, ViewGroup arg2) {
		BuyingDocument buyingDocument = lstBuyDoc.get(arg0);
		DecimalFormat df = new DecimalFormat("#.#");
		
		if(convertview==null){
			holder = new ViewHolder();
			
			LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertview=inflater.inflate(R.layout.adapter_purchaseorder_viewform13, arg2,false);
			
			holder.lbNamePro = (TextView)convertview.findViewById(R.id.lbNameProduct13);
			holder.valueName = (TextView)convertview.findViewById(R.id.valuesNamePro13);
			
			holder.lbTotal = (TextView)convertview.findViewById(R.id.lbTotalProduct13);
			holder.valTotal = (TextView)convertview.findViewById(R.id.valuesTotalPro13);
			
			convertview.setTag(holder);
		}else{
			holder = (ViewHolder)convertview.getTag();
		}

		holder.lbNamePro.setText("+"+" "+language.getString("ac_lien_STenSanPham")+": ");
		holder.lbNamePro.setTextColor(Color.YELLOW);
		
		holder.valueName.setText(buyingDocument.getName());

		holder.lbTotal.setText("    "+language.getString("total")+": ");
		holder.lbTotal.setTextColor(Color.YELLOW);
		
		holder.valTotal.setText(df.format(buyingDocument.getTotal())+"");
		
		return convertview;
	}

	public List<BuyingDocument> getLstBuyDoc() {
		return lstBuyDoc;
	}

	public void setLstBuyDoc(List<BuyingDocument> lstBuyDoc) {
		this.lstBuyDoc = lstBuyDoc;
	}


	public Bundle getLanguage() {
		return language;
	}

	public void setLanguage(Bundle language) {
		this.language = language;
	}

	public static class ViewHolder{
		TextView lbNamePro,valueName,lbTotal,valTotal;
	}

}
